1. Field of the Invention
The present invention relates to application programming interfaces (APIs) for computer systems. More specifically, the present invention relates to a method and an apparatus for extending the functionality of functions defined within an application programming interface.
2. Related Art
System software designers typically define an application program interface (API) in order to define a boundary across which application software accesses services provided by an application platform, such as a database or an operating system. For example, a database system typically includes an API defining how functions that can be called to perform various database operations. Similarly, an operating system typically includes an API defining how functions can be called to perform operating system tasks.
There are a number of advantages to using an API. An API insulates the application programmer from the intricacies of the operations performed by the underlying application platform. This simplifies the task of writing application programs. Additionally, applications designed around an API are modular, because they can be used with any application platform that supports the same API. For example, application that is written to access a first database within a first computer system through an API can easily be moved to a second computer system to access a second database if the second database also supports the same API.
Unfortunately, using an API also has a number of disadvantages. Application platforms typically evolve over time. Consequently, it is often necessary to add new functionality to an API. This is typically accomplished by shipping a new version of the application platform and the associated API to the customer, so that the customer can link the new version of the application platform and API into the customer""s application programs. This installation and linking process can be very inconvenient and time-consuming.
Furthermore, certain application programs may require more functionality than is provided by an API. Application platforms are also commonly used in conjunction with third party code, and this third party code often requires additional functionality that is not present in the API for the application platform. In order to provide this additional functionality, an application programmer or third party code developer must write external functions (if this is possible). Alternatively, the application programmer must somehow convince the designer of the application platform to incorporate the additional functionality into the application platform and the API. Either one of these options requires the application programmer or third party code developer to perform a large amount of work in order to make relatively minor changes to the functionality provided by functions defined within an API.
Hence, what is needed is a method and an apparatus that allows an API to be easily modified by an application programmer or a third party code developer to include additional functionality.
One embodiment of the present invention provides a system that modifies a function defined within an application programming interface (API) so that the function includes additional code. The system receives an additional code module to be integrated into the function within the API. The system also receives a command to integrate the additional code module into the function. This command is received through a pre-defined function within the API for integrating additional code into functions within the API. In response to the command, the system links the additional code into the function so that the additional code module is executed when the function is called.
In one embodiment of the present invention, linking the additional code module into the function involves linking the additional code module as an entry function that is executed at the beginning of the function.
In one embodiment of the present invention, linking the additional code module into the function involves linking the additional code module as an exit function that is executed at the end of the function.
In one embodiment of the present invention, linking the additional code module into the function involves linking the additional code module as a replacement for original code for the function. In a variation on this embodiment, the system configures the additional code module to selectively call the original code for the function.
In one embodiment of the present invention, the system receives a second additional code module to be integrated into the function. Upon receiving a second command to integrate the second additional code module into the function, the system links the second additional code module into the function so that the second additional code module is executed along with the additional code module when the function is called.
In one embodiment of the present invention, linking the second additional code module into the function involves chaining the second additional code module with the additional code module so that the second additional code module is executed in sequence with the additional code module. In a variation on this embodiment, chaining the second additional code module with the additional code module involves facilitating passing at least one parameter between the additional code module and the second additional code module.
In one embodiment of the present invention, linking the additional code module into the function involves configuring the linkage to ensure that executing the additional code module does not involve recursion.
In one embodiment of the present invention, linking the additional code module into the function involves ensuring an error code is propagated back to the function.
In one embodiment of the present invention, during development of the function, the system configures the function to include callback points for receiving the additional code module.